package com.usian.article.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.apis.article.ArticleUserControllerApi;
import com.usian.article.service.ArticleUserService;
import com.usian.model.article.pojos.ApAuthor;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * ClassName: ArticleUserController
 * Author:   WGG
 * Date:    2022-11-2022/11/14-19:33
 * Version: 1.0
 * Description:
 */
@RestController
@RequestMapping("/article/api/v1")
public class ArticleUserController implements ArticleUserControllerApi {

    @Autowired
    private ArticleUserService articleUserService;
    /**
     * 根据用户id查询作者信息
     * @param id
     * @return
     */
    @Override
    @GetMapping("/findByUserId/{id}")
    public ApAuthor findByUserId(@PathVariable("id") Integer id) {
        return articleUserService.getOne(Wrappers.<ApAuthor>lambdaQuery().eq(ApAuthor::getUserId,id));
    }

    /**
     * 根据id查询作者信息
     * @param id
     * @return
     */
    @Override
    @GetMapping("/findById/{id}")
    public ApAuthor findById(@PathVariable("id") Integer id) {
        return articleUserService.getOne(Wrappers.<ApAuthor>lambdaQuery().eq(ApAuthor::getId,id));
    }

    /**
     * 保存作者
     * @param apAuthor
     * @return
     */
    @Override
    @PostMapping("/save")
    public ResponseResult save(@RequestBody ApAuthor apAuthor) {
        articleUserService.save(apAuthor);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    @Override
    @GetMapping("/getByAuthor/{id}")
    public ApAuthor getByAuthor(@PathVariable Integer id) {
        return articleUserService.getByAuthor(id);
    }
}
